package com.zhang.controller;

import com.zhang.pojo.ShopBean;
import com.zhang.pojo.UserBean;
import com.zhang.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("shop")
@RestController
public class ShopController {

    @Autowired
    private IShopService shopService;

    @RequestMapping("findByUserId")
    public List<ShopBean> findByUserId(HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("user");
        return shopService.findByUserId(user.getUserId());
    }

    @RequestMapping("del")
    public String del(int shopId){
        shopService.del(shopId);
        return "ok";
    }

    @RequestMapping("add")
    public String add(int productId,HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("user");
        shopService.add(productId, user.getUserId());
        return "ok";
    }

    @RequestMapping("update")
    public String update(int shopId,int num){
        shopService.update(shopId,num);
        return "ok";
    }
}
